package com.xinxing.city.recoverycheck;

import android.app.Application;
import android.os.Build;
import android.util.Log;

import com.dianping.logan.Logan;
import com.dianping.logan.LoganConfig;
import com.dianping.logan.OnLoganProtocolStatus;
import com.google.inject.Module;
import com.xinxing.city.recoverycheck.modules.RecoveryModules;

import java.io.File;

import roboguice.RoboGuice;

public class App extends Application {
    private static final String FILE_NAME = "logan_v1";
    @Override
    public void onCreate() {
        super.onCreate();

        String model = Build.MODEL;
        String version = Build.VERSION.RELEASE;
        Log.e("app",version);
        if(model.contains("3288")){
            Constant.MOCK=true;
            Constant.FACTORY =Constant.XIAOZHI;
        }else if( model.contains("3568_r")){
            Constant.MOCK=false;
            Constant.FACTORY =Constant.CHENGKAI;
        }else{
            Constant.MOCK=false;
            Constant.FACTORY =Constant.ZHIYANYUAN;
        }
        initLogan();
        RoboGuice.setUseAnnotationDatabases(false);
        DI.setInjector(RoboGuice.getOrCreateBaseApplicationInjector(this, RoboGuice.DEFAULT_STAGE, getModules()));
    }
    private Module[] getModules()
    {
        Module[] modules = {
                new RecoveryModules()
        };

        return modules;
    }
    private void initLogan() {
        LoganConfig config = new LoganConfig.Builder()
                .setCachePath(getApplicationContext().getFilesDir().getAbsolutePath())
                .setPath(getApplicationContext().getExternalFilesDir(null).getAbsolutePath()
                        + File.separator + FILE_NAME)

                .setEncryptKey16("0123456789012345".getBytes())
                .setEncryptIV16("0123456789012345".getBytes())
                .setDay(24 * 60 * 60 * 1000)
                .build();
        Logan.init(config);
        Logan.setDebug(true);
        Logan.setOnLoganProtocolStatus(new OnLoganProtocolStatus() {
            @Override
            public void loganProtocolStatus(String cmd, int code) {
                Log.d("TAG", "clogan > cmd : " + cmd + " | " + "code : " + code);
            }
        });

    }
}
